package lab03.test14;

import java.net.ConnectException;
import java.sql.*;

import static java.lang.Class.forName;

public class Test {
    public static void main(String[] args) {

        Connection connection=null;

        Statement statement=null;

        ResultSet resultSet=null;

        String sql="select * from t_userinfo";
//        String s="inser into t_userinfo values('7709','小明','09999','xiaoming@qq.com')";

        try {
            Class.forName("com.mysql.jdbc.Driver");

                connection= DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                        "root",
                        "123456");

                statement=connection.createStatement();

//                statement.execute(s);

                resultSet=statement.executeQuery(sql);

                while(resultSet.next()){

                    System.out.println(resultSet.getString(1));
                    System.out.println(resultSet.getString(2));
                    System.out.println(resultSet.getString(3));
                    System.out.println(resultSet.getString(4));

                }


        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                statement.close();
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }

        }


    }
}
